home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / CD Audio Toolkit 1.0 / Source / CDSearchTrack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  4.7 KB  |  180 lines  |  [TEXT/MPS ]

  1. /*
  2.     CDSearchTrack - An XCMD to search to an audio track.
  3.     ©Apple Computer, Inc. 1988
  4.     All Rights Reserved.
  5.     
  6.     88/10/08    BL°B    First Version
  7.  
  8.     To compile and link this file using Macintosh Programmer's Workshop,
  9.  
  10.     C -q2 CDSearchTrack.c
  11.     link -sn Main=CDSearchTrack -sn STDIO=CDSearchTrack ∂
  12.          -sn INTENV=CDSearchTrack -rt XFCN=42 ∂
  13.          -m CDSEARCHTRACK CDSearchTrack.c.o "{CLibraries}"CRuntime.o ∂
  14.          "{CLibraries}"StdCLib.o ∂
  15.          -o HyperCommands
  16.          
  17.     This link directive puts the XCMD in the file "HyperCommands".
  18.     Substitute the name of the stack you want it in.  To move XCMDs
  19.     between stacks, use ResEdit.  They can be in an individual stack,
  20.     the Home stack, the HyperCard application, or the System File.
  21.     
  22. */
  23.  
  24. #include <cd.h>
  25.  
  26. /* prototype definitions for functions */
  27. void    ExtractTrackNo(char *, short *);
  28. OSErr    ASearch(XCmdBlockPtr, short, short, short);
  29.  
  30. /* **** WARNING:  DO NOT USE GLOBAL VARIABLES! **** */
  31.  
  32.  
  33. /************************************************************************
  34.  *
  35.  *  Function:        CDSearchTrack
  36.  *
  37.  *  Purpose:        search to a specific an audio track
  38.  *
  39.  *  Returns:        result of driver call to Search track
  40.  *                    normally 0, but could have parameter error or
  41.  *                    other error if non-existent track is specified
  42.  *
  43.  *  Side Effects:
  44.  *
  45.  *  Description:    We need two parameters, the play/pause flag and the
  46.  *                    track number.  Extract the track number and search 
  47.  *                    to it. Play if the play/pause flag tells you to.
  48.  *
  49.  ************************************************************************/
  50. pascal void
  51. CDSearchTrack(paramPtr)
  52.     XCmdBlockPtr    paramPtr;
  53. {
  54.     Str31    returnString;
  55.     OSErr    result;
  56.     short    trackNumber;
  57.     short    ioRefNum;
  58.     Handle    refHandle;
  59.     short    flag;
  60.     
  61.     /* Must be two parameters */
  62.     if ((paramPtr->paramCount) != 2)
  63.     {
  64.         /* Report error in parameters by returning -1 */
  65.         NumToStr(paramPtr, (long) -1, &returnString);
  66.         paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  67.         return;
  68.     }
  69.     
  70.     /* Get the global ioRefNum and convert it. */
  71.     refHandle = GetGlobal(paramPtr, GLOBALNAME);
  72.     ioRefNum = atoi(*(refHandle));
  73.     DisposHandle(refHandle);
  74.     ioRefNum &= 0xFFFF;            /* remove vRefNum; not needed. */
  75.     
  76.     /* First param is play/pause flag.  Convert it to a short */
  77.     flag = atoi(*(paramPtr->params[0]));
  78.     
  79.     /* Second param is track number.  Convert it to a BCD number */
  80.     ExtractTrackNo((char *)*(paramPtr->params[1]), &trackNumber);
  81.     
  82.     result = ASearch(paramPtr, ioRefNum, flag, trackNumber);
  83.     
  84.     /* Convert result to string & return it */
  85.     NumToStr(paramPtr, (long) result, &returnString);
  86.     paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
  87. }
  88.  
  89. /************************************************************************
  90.  *
  91.  *  Function:        ExtractTrackNo
  92.  *
  93.  *  Purpose:        Extract track number in BCD from PString
  94.  *
  95.  *  Returns:        nothing
  96.  *
  97.  *  Side Effects:    *track gets a new value
  98.  *
  99.  *  Description:    Extract track number in BCD from Cstring "name".
  100.  *                    "name" is always of the form "XX", where XX
  101.  *                    ranges from "1"  to "99"
  102.  *                    (You can't have more than 99 tracks on a compact disc.
  103.  *                    Bet you didn't know that, did you?  Right in the "Yellow
  104.  *                    Book" specification of compact disc encoding.)
  105.  *
  106.  ************************************************************************/
  107. void
  108. ExtractTrackNo(name, track)
  109. char        *name;
  110. short        *track;
  111. {
  112.     short    t;
  113.         
  114.     t = 0;
  115.     while (*name != 0)
  116.     {
  117.         t *= 16;
  118.         t += *name - '0';
  119.         name++;
  120.     }
  121.     
  122.     *track = t;    
  123. }
  124.  
  125. /************************************************************************
  126.  *
  127.  *  Function:        ASearch
  128.  *
  129.  *  Purpose:        start Searching an audio track
  130.  *
  131.  *  Returns:        OSErr.  Probably either
  132.  *                        noErr        everything's hunky-dory!
  133.  *                        paramErr    you messed up the call somehow.
  134.  *
  135.  *  Side Effects:    starts search.
  136.  *
  137.  *  Description:    The track that you pass in is the location to which
  138.  *                    you want to search.  You can then start play with
  139.  *                    a pause command.
  140.  *
  141.  ************************************************************************/
  142. OSErr
  143. ASearch(paramPtr, refNum, flag, track)
  144. XCmdBlockPtr    paramPtr;
  145. short    refNum;
  146. short    flag;        /* 0 = search & pause, 1 = search & play */
  147. short    track;        /* track number to search to */
  148. {
  149.     CDParam    myPB;
  150.     short        playMode;
  151.     Handle        refHandle;
  152.     
  153.     /* Get the global ioRefNum and convert it. */
  154.     refHandle = GetGlobal(paramPtr, PLAYMODE);
  155.     playMode = atoi(*(refHandle));
  156.     DisposHandle(refHandle);
  157.     
  158.     myPB.ioCompletion = 0;
  159.     myPB.ioNamePtr = (char *) 0;
  160.     myPB.ioVRefNum = 1;
  161.     myPB.ioCRefNum = refNum;
  162.     myPB.csCode = ASEARCH;
  163.     
  164.     myPB.csParam[0] = 0;
  165.     myPB.csParam[1] = TRACKADDR;
  166.     myPB.csParam[2] = 0;
  167.     myPB.csParam[3] = 0;
  168.     myPB.csParam[4] = 0;
  169.     myPB.csParam[5] = track;
  170.     myPB.csParam[6] = 0;
  171.     myPB.csParam[7] = flag;
  172.     myPB.csParam[8] = 0;
  173.     myPB.csParam[9] = playMode;
  174.     return (PBControl(&myPB, false));
  175. }
  176.  
  177.  
  178. /* C routines for HyperCard callbacks */
  179. #include <XCmdGlue.inc.c>
  180.